/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package war2100.game.states.menu;

import java.io.File;
import java.io.FileInputStream;
import java.io.ObjectInputStream;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.newdawn.slick.Input;

import war2100.Game;
import war2100.entity.Map;
import war2100.entity.SerializableMap;
import war2100.game.GameSession;
import war2100.game.Player;
import war2100.game.states.GameplayState;

/**
 *
 * @author efischer
 */
public class StartGameHandler implements MenuButtonListener
{
    private Game game;
    
    public StartGameHandler(Game game)
    {
        this.game = game;
    }
    
    @Override
    public void MenuButtonClicked() 
    {
        File file = new File("./map/mission_01.map");
        ObjectInputStream is;
        Map map = null;
        try
        {
            is = new ObjectInputStream(new FileInputStream(file));
            SerializableMap sMap = (SerializableMap) is.readObject();
            map = sMap.getMap(this.game);
        }
        catch(Exception ex)
        {
            Logger.getLogger(StartGameHandler.class.getName()).log(Level.SEVERE, ex.getMessage());
        }
        
        // spaeter soll die GameSession durch Menues entstehen
        GameSession session = new GameSession(new Player(1,Input.KEY_W, Input.KEY_S, Input.KEY_D, Input.KEY_A, Input.KEY_SPACE, true));
        
        game.addState(new GameplayState(map, session, game.getPrototypes()));
		try
		{
		game.getState(GameplayState.ID).init(game.getContainer(), game);
		}catch(Exception ex)
		{
			
		}
        game.enterState(GameplayState.ID);
    }
    
}
